<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" id="i1">
    <input type="button" value="平方" onclick="f()">
    <div>结果:<span>0</span></div>
    <script>
        function f() {
            let i = document.querySelector("#i1");
            let s = document.querySelector("span");
            if (isNaN(i.value)) {
                s.innerText = "输入错误";
                return;
            }
            //s.innerText = i.value * i.value;
            //第一种方式,强制转换为数值
            //s.innerText = i.value*1 + i.value*1;
            //第二种方式,parseFloat()能将字符串转换为整数或者小数
            s.innerText = parseFloat(i.value) + parseFloat(i.value);

        }
    </script>
</body>
</html>